<template>
  <el-dialog
    title="收货地址"
    :visible="chkDialogFormVisible"
    width="27%"
    @close="chkDialogVisible"
    destroy-on-close
  >
    <el-form :model="chkForm" ref="chkRef" :rules="chkRules">
      <el-form-item prop="chkState">
        <el-radio v-model="chkForm.chkState" label="1">通过</el-radio>
        <el-radio v-model="chkForm.chkState" label="2"
          >拒绝</el-radio
        ></el-form-item
      >
      <el-form-item prop="chkRemarks">
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入审核意见"
          v-model="chkForm.chkRemarks"
          clearable
        >
        </el-input
      ></el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="chkDialogVisible">取 消</el-button>
      <el-button type="primary" @click="addChk">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getChk } from '@/api/hmmm/questions'

export default {
  name: 'QuestionsCheck',
  components: {},
  props: {
    chkDialogFormVisible: {
      type: Boolean,
      default: false
    },
    chkID: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      chkRules: {
        chkRemarks: [
          { required: true, message: '请输入审核意见', trigger: 'blur' }
        ]
      },
      chkForm: {
        chkState: '1',
        chkRemarks: ''
      }
    }
  },
  computed: {},
  watch: {},
  methods: {
    chkDialogVisible() {
      this.$refs.chkRef.resetFields()
      this.$emit('update:chkDialogFormVisible', false)
    },
    async addChk() {
      await this.$refs.chkRef.validate()
      if (this.chkForm.chkState === '1') {
        try {
          await getChk({
            id: this.chkID,
            chkRemarks: this.chkForm.chkRemarks,
            chkState: 1
          })
          this.$message.success('审核成功！')
          this.chkDialogVisible()
          this.$emit('updateChk')
        } catch (error) {
          this.$message.error('审核失败，请稍后再试')
        }
      } else {
        await getChk({
          id: this.chkID,
          chkRemarks: this.chkForm.chkRemarks,
          chkState: 2
        })
        this.$message.success('审核已拒绝！')
        this.chkDialogVisible()
        this.$emit('updateChk')
      }
    }
  },
  created() {},
  mounted() {}
}
</script>
<style scoped lang="less"></style>
